package data.promotion;
import java.util.Calendar;
import data.ItemData;
import data.ItemRecord;
import data.Record;

public class ItemGiftRecord extends Record{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String item_id;
	
	private String gift_id;
	
	private Calendar start_time;
	
	private Calendar end_time;
	
	
	
	
	public ItemGiftRecord(String item_id,String gift_id,Calendar start_time,Calendar end_time){
		this.set(item_id, gift_id, start_time, end_time);
	}
	
	
	
	public void set(String item_id,String gift_id,Calendar start_time,Calendar end_time){
		this.item_id=item_id;
		this.gift_id=gift_id;
		this.start_time=start_time;
		this.end_time=end_time;
	}
	
	
	
	public String getItemID(){
		return item_id;
	}
	
	public String getGiftID(){
		return gift_id;
	}
	
	public Calendar getStartTime(){
		return start_time;
	}
	
	public Calendar getEndTime(){
		return start_time;
	}
	
	
	public boolean isDuringTime(){
		Calendar time=Calendar.getInstance();
		return this.isDuringTime(time);
	}
	
	public boolean isDuringTime(Calendar time){
	    return (time.after(start_time)&&time.before(end_time));
	}
	
	
	public String getGiftID(ItemRecord item){
		if(this.isDuringTime()&&item.getID().equals(item_id)){
			return gift_id;
		}
		return null;
	}
	
	
	public String getGiftID(ItemData itemList){
		ItemRecord item=itemList.getItemByID(item_id);
		if(this.isDuringTime()&&item!=null){
			return gift_id;
		}
		return null;
	}
}
